from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, UnicodeText
from sqlalchemy.orm import relation
from .base import Base, user_roles
from sqlalchemy.databases import mysql

__all__ = ['User']

class User(Base):
    __tablename__ = 'users'
    
    id = Column(Integer, primary_key=True)
    login = Column(mysql.MSString(255), nullable=False, unique=True)
    password = Column(UnicodeText, nullable=False)
    email = Column(mysql.MSString(255), nullable=False, unique=True)
    name = Column(UnicodeText)
    
    roles = relation('Role', secondary=user_roles)
    
    def __init__(self, login, password, email, name=None):
        self.login = login
        self.password = password
        self.email = email
        self.name = name
        
    def __repr__(self):
        return "<User('%s', '%s', '%s', '%s')>" % (self.login, self.password, self.email, self.name)